package com.usian.common.interceptor;

import com.usian.utils.threadlocal.ThreadLocalUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServiceInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        String userId = request.getHeader("userId");
        if (userId !=null) ThreadLocalUtils.setUser(Integer.parseInt(userId));
        String refreshToken = request.getHeader("refreshToken");
        if (refreshToken!=null)response.setHeader("refreshToken",refreshToken);
        return true;
    }
}
